﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Timers;
using DWH.Data;
using DWH.Utils;

namespace DWH.PP.Push
{
    public abstract class PageAttachmentDownloadWorkerBase : PPTaskBase
    {      
        public int WorkerInstanceCount { get; set; }

        public BlockingCollection<PageAttachment> ProcessingCollection { get; private set; }        

        public PageAttachmentDownloadWorkerBase()
        {
            ProcessingCollection = new BlockingCollection<PageAttachment>();
        }

        public override void Initialize()
        {
            InitializeTaskInfoFromDB();

            WorkerInstanceCount = Int32.Parse(ExtendData[DWHConstants.KEY_WORKER_INSTANCE_COUNT]);
        }

        public override void Run()
        {
            for (int i = 0; i < WorkerInstanceCount; i++)
            {
                Task t = new Task(DoWork);
                t.Start();
            }
        }        

        public abstract void DoWork();

        public override void Reset()
        {

        }
    }
}
